View Javadoc
1 /* ====================================================================
2 * The Apache Software License, Version 1.1
3 *
4 * Copyright (c) 2000 The Apache Software Foundation. All rights
5 * reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * 3. The end-user documentation included with the redistribution,
20 * if any, must include the following acknowledgment:
21 * "This product includes software developed by the
22 * Apache Software Foundation (http://www.apache.org/)."
23 * Alternately, this acknowledgment may appear in the software itself,
24 * if and wherever such third-party acknowledgments normally appear.
25 *
26 * 4. The names "Apache" and "Apache Software Foundation" must
27 * not be used to endorse or promote products derived from this
28 * software without prior written permission. For written
29 * permission, please contact apache@apache.org.
30 *
31 * 5. Products derived from this software may not be called "Apache",
32 * nor may "Apache" appear in their name, without prior written
33 * permission of the Apache Software Foundation.
34 *
35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46 * SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This software consists of voluntary contributions made by many
50 * individuals on behalf of the Apache Software Foundation. For more
51 * information on the Apache Software Foundation, please see
52 * <http://www.apache.org/>;.
53 *
54 * Portions of this software are based upon public domain software
55 * originally written at the National Center for Supercomputing Applications,
56 * University of Illinois, Urbana-Champaign.
57 */
58
59 package org.troublescope.tools;
60
61 import java.io.File;
62
63 import org.apache.tools.ant.BuildException;
64 import org.apache.velocity.context.Context;
65 import org.apache.velocity.texen.ant.TexenTask;
66
67 /***
68 * An Ant task used to generate the JNLP file for a particular evaluation.
69 */
70 public class TroubleScopeJnlpTask extends TexenTask
71 {
72
73 private String baseUrl;
74 private File basedir;
75 private String applicationId;
76 private String evaluationId;
77 private String clientType;
78
79 /***
80 * Create a new <code>TroubleScopeJnlpTask</code>.
81 */
82 public TroubleScopeJnlpTask()
83 {
84 }
85
86 /***
87 * Returns the base directory.
88 */
89 public File getBasedir()
90 {
91 return basedir;
92 }
93
94 /***
95 * Sets the base directory.
96 */
97 public void setBasedir(File aBasedir)
98 {
99 basedir = aBasedir;
100 }
101
102 /***
103 * Returns the base url.
104 */
105 public String getBaseUrl()
106 {
107 return baseUrl;
108 }
109
110 /***
111 * Sets the base url.
112 */
113 public void setBaseUrl(String aBaseUrl)
114 {
115 baseUrl = aBaseUrl;
116 }
117
118 /***
119 * Returns the evaluation id.
120 */
121 public String getEvaluationId()
122 {
123 return evaluationId;
124 }
125
126 /***
127 * Set the evaluation id.
128 */
129 public void setEvaluationId(String anEvaluationId)
130 {
131 evaluationId = anEvaluationId;
132 }
133
134 /***
135 * Returns the application id.
136 */
137 public String getApplicationId()
138 {
139 return applicationId;
140 }
141
142 /***
143 * Sets teh application id.
144 */
145 public void setApplicationId(String anApplicationId)
146 {
147 applicationId = anApplicationId;
148 }
149
150 /***
151 * Returns the client type.
152 */
153 public String getClientType()
154 {
155 return clientType;
156 }
157
158 /***
159 * Set the client type.
160 */
161 public void setClientType(String aClientType)
162 {
163 clientType = aClientType;
164 }
165
166 /***
167 * Execute this task.
168 */
169 public void execute() throws BuildException
170 {
171 setUseClasspath(true);
172 setControlTemplate("org/troublescope/tools/client-jnlp.vm");
173 File evalDir = new File(getBasedir(), getApplicationId() + "/evaluations/" + getEvaluationId());
174 setOutputDirectory(evalDir);
175 setOutputFile(getEvaluationId() + ".jnlp");
176 super.execute();
177 }
178
179 /***
180 * Populate the initial context.
181 */
182 protected void populateInitialContext(Context context)
183 throws Exception
184 {
185 super.populateInitialContext(context);
186 putContextAttribute(context, "baseUrl", getBaseUrl());
187 putContextAttribute(context, "clientType", getClientType());
188 putContextAttribute(context, "applicationId", getApplicationId());
189 putContextAttribute(context, "evaluationId", getEvaluationId());
190 }
191
192 /***
193 * Put a value into the context.
194 */
195 static private void putContextAttribute(Context context,
196 String name,
197 String value)
198 {
199 if (value == null) {
200 throw new BuildException("Attribute '" + name + "' required");
201 }
202 context.put(name, value);
203 }
204
205 }
This page was automatically generated by Maven